<?php

/**
 * @Author: king
 * @Date:   2019-05-05 19:17:27
 * @Last Modified by:   king
 * @Last Modified time: 2019-05-05 19:17:52
 */

namespace App\Tools\Validates;

use App\Tools\Validate;

class Counselor extends Validate
{
    protected $rule = [
        'type' => 'in:0,1,2',
        'price' => 'in:0,1,2,3,4',
        'level' => 'in:0,1,2,3,4',
        'grade' => 'in:0,1,2,3,4',
//        'search' => 'require',
        'name' => 'require|chsAlphaNum|length:1,25',
        'telphone' => 'require|checkTel|length:11',
        'id_number' => 'require|length:18',
        'ali_number' => 'checkAli',
        'left_pic' => 'require',
        'right_pic' => 'require',
        'intro' => 'require|length:0,100',
        'step' => 'require',
        'nickname' => 'require|chsAlphaNum|length:1,10',
        'pid' => 'require|number',
        'content' => 'require',
        'time' => 'require',
        'status' => 'require|number|in:1,2',
        'cid' => 'require|number',
        'alipay_account' => 'require|checkAli'
    ];

    protected $message = [
        'type.in' => '未知类型',
        'price.in' => '价格范围超出',
        'level.in' => '级别超出',
        'grade.in' => '星级未知',
        'name.require' => '姓名必填',
        'name.chsAlphaNum' => '姓名只能是汉字、字母和数字',
        'name.length' => '姓名长度超出',
        'telphone.require' => '手机号码必填',
        'telphone.checkTel' => '手机号码违规',
        'telphone.length' => '手机号码违规',
        'id_number.require' => '身份证号码必填',
        'id_number.length' => '身份证号码违规',
        'ali_number.checkAli' => '支付宝账号违规',
        'left_pic.require' => '身份证正面照必传',
        'right_pic.require' => '身份证反面照必传',
        'intro.require' => '自我介绍必填',
        'intro.length' => '内容长度超出范围',
        'step.require' => '未知操作',
        'nickname.require' => '姓名必填',
        'nickname.chsAlphaNum' => '姓名只能是汉字、字母和数字',
        'nickname.length' => '姓名长度超出',
        'pid.require' => '测评类型未知',
        'content.require' => '测评结果信息未知',
        'time' => '测评时间未知',
        'status' => '接单状态未知',
        'cid' => '未知的咨询师',
        'alipay_account.require' => '支付宝账号必填',
        'alipay_account.checkAli' => '支付宝账号违规',
    ];

    protected $scene = [
        'index' => [
            'type',
            'price',
            'level',
            'grade',
        ],
        'auth' => [
            'name',
            'telphone',
            'id_number',
            'ali_number',
            'left_pic',
            'right_pic',
            'intro',
            'step',
            'nickname'
        ],
        'ExamineContent' => [
            'pid'
        ],
        'SubmitExamine' => [
            'pid',
            'content',
            'time'
        ],
        'IsTakeOrder' => [
            'status'
        ],
        'CounselorHome' => [
            'cid'
        ],
        'getTag' => [
            'type'
        ],
        'bindAli' => [
            'name',
            'alipay_account'
        ],
        
        'TimeRemaining' => [
            'pid'
        ]
    ];

    /**
     * 验证手机格式是否正确
     * @param $value
     * @return bool
     */
    public function checkTel($value)
    {
        if (preg_match("/^1[3456789]{1}\d{9}$/", $value)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 验证支付宝账号格式是否正确
     * @param $value
     * @return bool
     */
    public function checkAli($value)
    {
        if (preg_match("/^\w+([-_.]\w+)*@\w+([-_.]\w+)*(\.\w+){0,3}$/i", $value)) {
            return true;

        } elseif (preg_match("/^1[3456789]{1}\d{9}$/", $value)) {

            return true;

        } else {

            return false;

        }
    }

}